package AnimalCry;

abstract class Animal {
    abstract void cry();
    abstract String getAnimalname();
}
class Cat extends Animal{
    void cry(){
        System.out.println("叫声：miaomiao~");
    }
    String getAnimalname(){
        return "小猫";
    }
}
class Dog extends Animal{
    void cry(){
        System.out.println("叫声：wangwang~");
    }
    String getAnimalname(){
        return "小狗";
    }
}
class Simulator{
    Animal animal;
    void playSound(Animal animal){
        this.animal=animal;
    }
    void showAnimal(){
        System.out.println("动物：" + animal.getAnimalname());
        animal.cry();
    }
}
 class AnimalCry {
    public static void main(String[] args){
       Simulator animal=new Simulator();
       animal.playSound(new Dog());
       animal.showAnimal();
       animal.playSound(new Cat());
       animal.showAnimal();
    }

}

